using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Models;
using ConsoleApi.Services.Console;
using MESData.ErrorCode;

namespace ConsoleApi.Controllers
{
    /// <summary>
    /// 采购订单控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class PurchaseOrderController : ControllerBase
    {
        private readonly IConsoleService _consoleService;

        public PurchaseOrderController(IConsoleService consoleService)
        {
            _consoleService = consoleService;
        }

        /// <summary>
        /// 获取采购订单列表
        /// </summary>
        [HttpGet]
        public async Task<ApiResult<PagedResultDto<PurchaseOrderDto>>> GetPurchaseOrders([FromQuery] PurchaseOrderQueryDto query)
        {
            return await _consoleService.GetPurchaseOrdersAsync(query);
        }

        /// <summary>
        /// 获取采购订单详情
        /// </summary>
        [HttpGet("{id}")]
        public async Task<ApiResult<PurchaseOrderDto>> GetPurchaseOrder(int id)
        {
            return await _consoleService.GetPurchaseOrderAsync(id);
        }

        /// <summary>
        /// 创建采购订单
        /// </summary>
        [HttpPost]
        public async Task<ApiResult<PurchaseOrderDto>> CreatePurchaseOrder([FromBody] PurchaseOrderDto dto)
        {
            return await _consoleService.CreatePurchaseOrderAsync(dto);
        }

        /// <summary>
        /// 更新采购订单
        /// </summary>
        [HttpPut]
        public async Task<ApiResult<PurchaseOrderDto>> UpdatePurchaseOrder([FromBody] PurchaseOrderDto dto)
        {
            return await _consoleService.UpdatePurchaseOrderAsync(dto);
        }

        /// <summary>
        /// 删除采购订单
        /// </summary>
        [HttpDelete("{id}")]
        public async Task<ApiResult<bool>> DeletePurchaseOrder(int id)
        {
            return await _consoleService.DeletePurchaseOrderAsync(id);
        }
    }
} 